<!DOCTYPE html>
<html>
<head>
	<title>我的订单 - 传智商城</title>
	<meta charset="UTF-8">
	<link rel="stylesheet" href="./Public/Home/css/style.css"/>
	<script src="./Public/Common/js/jquery.min.js"></script>
</head>
<body>
<?php
  include_once 'top.php';   //include 可以把其他的php页面包含进入当前的页面位置
?>
<div class="box">
	<?php include_once 'header.php'; ?>
	<?php include_once 'nav.php';?>
<div class="usercenter">
<ul class="menu left">
	<li><a href="/User/index.html" id="User_index">个人信息</a></li>
	<li><a href="/Order/index.html" id="Order_index">我的订单</a></li>
	<li>我的关注</li>
	<li><a href="/User/addr.html" id="User_addr">收货地址</a></li>
	<li>消费记录</li>
	<li><a href="/Cart/index.html" id="Cart_index">购物车</a></li>
</ul>
<script>
$("#Order_index").addClass("curr");
</script>
<?php include_once 'islogin.php'; ?>
<div class="content left">我的订单
    <?php
        $userId=$_COOKIE['czuid'];
        //1.连接数据库
        $link=  mysqli_connect("localhost", "root", "");//创建数据库的连接
        mysqli_select_db($link, "itcast");//选择你要操作的数据库
        mysqli_set_charset($link, "utf8");//设置数据库连接的字符编码
        //2.操作数据表，写SQL模板
        $sql="SELECT * FROM shop_order WHERE user_id=$userId;";
        $result=  mysqli_query($link, $sql); //mysqli_query 返回结果：如果select返回结果资源,如果delete update insert返回的true或false
        //3.处理结果数据
        //$row=  mysqli_fetch_array($result);//返回一行数据包含索引数组和关联数组
        //$row= mysqli_fetch_assoc($result);//返回一行数据关联数组
        //$row=  mysqli_fetch_row($result);//返回一行数据索引数组
        while($row= mysqli_fetch_assoc($result)){
            $orderCode=$row['order_code'];//订单编码
            $orderTime=$row['add_time'];//下单时间
            $totalPrice=$row['price'];//总价
            $address=$row['address'];
            ?>
            <table class="order">
              <tr class="tr-tit">
                <th class="txt-left" colspan="2">订单号:<?php echo $orderCode ?>　下单时间：<?php echo $orderTime ?>　<a href="#">立即支付</a>　<a href="#" data-id="7" class="cancel">取消订单</a></th>
                <th width="100">总价<span>￥<?php echo $totalPrice ?></span></th>
              </tr>
            <?php
               //内循环 订单详情数据
               $sqlDetail="SELECT g.name AS good_name,d.good_id AS good_id, d.good_num AS good_num,d.good_price AS good_price FROM shop_order_detail d,shop_goods g WHERE g.id=d.good_id AND order_code='$orderCode';";
               $resultDetail=  mysqli_query($link, $sqlDetail); //mysqli_query 返回结果：如果select返回结果资源,如果delete update insert返回的true或false
               while($row= mysqli_fetch_assoc($resultDetail)){
                   $name=$row['good_name'];
                   $goodId=$row['good_id'];
                   $goodNum=$row['good_num'];
                   $goodPrice=$row['good_price'];
            ?>
                <tr>
                  <td class="gname"><a href="goods.php?id=<?php echo $goodId; ?>" target="_blank"><?php echo $name; ?></td>
                  <td class="txt-center"><?php echo $goodNum; ?>件</td>
                  <td class="txt-center"><span>￥<?php echo $goodPrice; ?></span></td>
                </tr>            
            <?php
               }
            ?>
             
              <tr>
                <td colspan="3">收件地址：<?php echo $address; ?></td>
              </tr>
            </table>
    
            <?php
    
        }
    ?>
        
        <table class="order">
          <tr class="tr-tit">
            <th class="txt-left" colspan="2">订单号：ITCAST6　下单时间：2015-05-21 18:31:25　<a href="#">立即支付</a>　<a href="#" data-id="6" class="cancel">取消订单</a></th>
            <th width="100">总价<span>￥172.80</span></th>
          </tr>
          <tr>
            <td class="gname"><a href="/Index/goods/id/45.html" target="_blank">PHP网站开发实例教程</td>
            <td class="txt-center">1件</td>
            <td class="txt-center"><span>￥48.80</span></td>
          </tr>
          <tr>
            <td class="gname"><a href="/Index/goods/id/46.html" target="_blank">MySQL数据库入门</td>
            <td class="txt-center">2件</td>
            <td class="txt-center"><span>￥39.50</span></td>
          </tr>
          <tr>
            <td class="gname"><a href="/Index/goods/id/51.html" target="_blank">HTML+CSS+JavaScript网页制作案例教程</td>
            <td class="txt-center">1件</td>
            <td class="txt-center"><span>￥45.00</span></td>
          </tr>
          <tr>
            <td colspan="3">收件地址：北京市,市辖区,昌平区,建材城西路金燕龙办公楼一层，收件人：张三，联系电话：13812345678</td>
          </tr>
        </table>
      </div>

	<form method="post" id="form">
		<input type="hidden" id="target" name="id">
	</form>
	<div class="clear"></div>
</div>
<script>
	$(".cancel").click(function(){
		if(confirm('您确定要取消订单？')){
			$("#target").val($(this).attr("data-id"));
			$("#form").attr("action","/Order/cancel.html").submit();
		}
	});
</script>
	<div class="service">
		<ul><li>购物指南</li><li>配送方式</li><li>支付方式</li>
			<li>售后服务</li><li>特色服务</li><li>网络服务</li>
		</ul>
	</div>
	<div class="footer">传智商城·本项目仅供学习使用</div>
</div>
</body>
</html>